package javanlp;

import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
import opennlp.tools.util.InvalidFormatException;

public class PostgresDetect{
	public static void main(String[] args) 
                throws InvalidFormatException,IOException, 
                SQLException, Exception {
        int count=1;
        Class.forName("org.postgresql.Driver"); 
        String url = "jdbc:postgresql://localhost/postgres";
        String user = "postgres", passwd = "cinvprobit";
        Connection con = DriverManager.getConnection(url,user,passwd);
        Statement stmt = con.createStatement();
        while (count<5){
            ResultSet rs = stmt.executeQuery(
                "select id, text from java2 where id = " + count);
            while (rs.next()){
                int s1 = rs.getInt("id");
                String s2 = rs.getString("text");    
                String fld = "C:/Users/lenovolap/Dropbox/java/NLP.models/";
                String trainedModel = fld+"/en-sent.zip";
                try (InputStream is = new FileInputStream(trainedModel)) 
                {
                  SentenceModel model = new SentenceModel(is);
                  SentenceDetectorME sdetector = new SentenceDetectorME(model);
                  String st[] = sdetector.sentDetect(s2);
                  for (int i=0; i<st.length;i++){
                    System.out.println(st[i]);
                  }
               }
             }
            if (rs != null) { rs.close();}
            count++;
        }
       if (con != null) { con.close(); }
     }
}